package com.ruoyi.health.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.health.domain.BmService;
import com.ruoyi.health.service.IBmServiceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 便民服务Controller
 *
 * @author dalian
 * @date 2023-08-06
 */
@RestController
@RequestMapping("/health/healthBmService")
public class BmServiceController extends BaseController {
    @Autowired
    private IBmServiceService bmServiceService;

    /**
     * 查询便民服务列表
     */
    @PreAuthorize("@ss.hasPermi('health:healthBmService:list')")
    @GetMapping("/list")
    public TableDataInfo list(String itemName,
                              Long staffNumMin,
                              Long staffNumMax,
                              Long sinceMin,
                              Long sinceMax,
                              Long serviceItemId,
                              Long typeId,  //有serviceItemId时，typeId失效
                              Long region1Id,
                              Long region2Id) {
        startPage();
        List<BmService> list = bmServiceService.selectBmServiceList(itemName,
                staffNumMin, staffNumMax,
                sinceMin, sinceMax,
                serviceItemId, typeId,
                region1Id, region2Id);
        return getDataTable(list);
    }


    /**
     * 获取便民服务详细信息
     */
    @PreAuthorize("@ss.hasPermi('health:healthBmService:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(bmServiceService.selectBmServiceById(id));
    }

    /**
     * 新增便民服务
     */
    @PreAuthorize("@ss.hasPermi('health:healthBmService:add')")
    @Log(title = "便民服务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BmService bmService) {
        bmService.setCreateBy(getUsername());
        return toAjax(bmServiceService.insertBmService(bmService));
    }

    /**
     * 修改便民服务
     */
    @PreAuthorize("@ss.hasPermi('health:healthBmService:edit')")
    @Log(title = "便民服务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BmService bmService) {
        return toAjax(bmServiceService.updateBmService(bmService));
    }

    /**
     * 删除便民服务
     */
    @PreAuthorize("@ss.hasPermi('health:healthBmService:remove')")
    @Log(title = "便民服务", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bmServiceService.deleteBmServiceByIds(ids));
    }
}
